#include <stdio.h>
#include <stdlib.h>
#define MAX_STACK_SIZE 100
#define INCREASE_SIZE 10

typedef struct Stack
{
    int stacksize;
    int *top;
    int *base;
}Stack;
void InitStack(Stack *S);
void InitStack(Stack *S)
{
    S->base=(int *)malloc(MAX_STACK_SIZE*sizeof(int));
    if(S->base==NULL)
    {
        printf("ERROR!");
        return;
    }
    S->top=S->base;
    S->stacksize=MAX_STACK_SIZE;
}
void Push(Stack *S,int elem);
void Push(Stack *S,int elem)
{
    if(S->top-S->base==S->stacksize)
    {
        S->base=(int *)realloc(S->base,(INCREASE_SIZE+MAX_STACK_SIZE)*sizeof(int));
        if(!S->base)
        {
            printf("OVERFLOW");
            return;
        }
        S->top=S->base+S->stacksize;
        S->stacksize+=INCREASE_SIZE;
    }
    *S->top=elem;
    S->top++;
}
void Pop(Stack *S);
void Pop(Stack *S)
{
    if(S->base==S->top)
    {
        printf("EMPTY");
        return;
    }
    int elem=*--S->top;
    printf("%d\n",elem);
}
void GetTop(Stack *S,int *elem);
void GetTop(Stack *S,int *elem)
{
    if(S->base==S->top)
    {
        printf("EMPTY");
        return;
    }
    *elem=*(S->top-1);
}
int main()
{
    Stack S;
    int elem;
    InitStack(&S);
    Push(&S,1);
    Push(&S,2);
    Push(&S,3);
    Push(&S,4);
    Push(&S,5);
    Pop(&S);
    Pop(&S);
    GetTop(&S,&elem);
    printf("%d\n",elem);
    Pop(&S);
}